%   This function generates figure X of KO
%   The function computes the absolute deviations and codes them as positive or negative
%   The figure plots different markers for the different signed deviations
function [N] = fig_3_code(res_tab)
%dev_U = [];
%dev_M = [];
[g,N] = size(res_tab);
x = [1,2,3,4,5];
p = 1;
for n = 1:5
    a1_u = res_tab(1,x(1,n)).resa(:,2);
    a2_u = res_tab(1,x(1,n)).resa(:,3);
    a3_u = res_tab(1,x(1,n)).resa(:,4);
    a1_m = res_tab(1,x(1,n)).resb(:,2);
    a2_m = res_tab(1,x(1,n)).resb(:,3);
    a3_m = res_tab(1,x(1,n)).resb(:,4);
    dev1_u = abs(a1_u);
    dev2_u = abs(a2_u);
    dev3_u = abs(a3_u);
    dev1_m = abs(a1_m);
    dev2_m = abs(a2_m);
    dev3_m = abs(a3_m);
    mpos = ~logical(res_tab(1,x(1,n)).resb(:,7));
    dev1_up = dev1_u(mpos);
    dev1_mp = dev1_m(mpos);   
    dev1_un = dev1_u(~mpos);
    dev1_mn = dev1_m(~mpos);
    
    dev2_up = dev2_u(mpos);
    dev2_mp = dev2_m(mpos);   
    dev2_un = dev2_u(~mpos);
    dev2_mn = dev2_m(~mpos);
    
    dev3_up = dev3_u(mpos);
    dev3_mp = dev3_m(mpos);   
    dev3_un = dev3_u(~mpos);
    dev3_mn = dev3_m(~mpos);
    
    subplot(5,6,p),
    plot(dev1_up,dev1_mp,'k.',dev1_un,dev1_mn,'ko',[0:0.01:1],[0:0.01:1],'k-'),xlabel('Separable'),ylabel('Nonseparable'),axis([0 1 0 1]),axis square
    set(gca,'XTick',0:0.5:1),set(gca,'YTick',0:0.5:1)
    if p == 1
        title('\tau_1')
    end,
    p = p + 1;
    subplot(5,6,p),
    plot(dev2_up,dev2_mp,'k.',dev2_un,dev2_mn,'ko',[0:0.01:1],[0:0.01:1],'k-'),xlabel('Separable'),ylabel('Nonseparable'),axis([0 1 0 1]),axis square
    set(gca,'XTick',0:0.5:1),set(gca,'YTick',0:0.5:1)
    if p == 2
        title('\tau_2')
    end
    p = p + 1;
    subplot(5,6,p),
    plot(dev3_up,dev3_mp,'k.',dev3_un,dev3_mn,'ko',[0:0.01:1],[0:0.01:1],'k-'),xlabel('Separable'),ylabel('Nonseparable'),axis([0 1 0 1]),axis square
    set(gca,'XTick',0:0.5:1),set(gca,'YTick',0:0.5:1)
    if p == 3
        title('\tau_3')
    end,
    p = p + 4;
end,
